﻿using System.Collections.Generic;
using Terraria.ModLoader;
using Terraria.WorldBuilding;

namespace 过度世界生成
{

    public class ExcessiveWorld : ModSystem
    {
        public override void ModifyWorldGenTasks(List<GenPass> tasks, ref double totalWeight)
        {
            int marbleIndex = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Marble")); // 大理石
            GenPass marblePass = tasks[marbleIndex];
            for (int i = 1; i < ModContent.GetInstance<Configs>().MarbleInt + 1; i++)
            {
                tasks.Insert(marbleIndex + i, marblePass);
            }
            int graniteIndex = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Granite")); // 花岗岩
            GenPass granitePass = tasks[graniteIndex];
            for (int j = 1; j < ModContent.GetInstance<Configs>().GraniteInt + 1; j++)
            {
                tasks.Insert(graniteIndex + j, granitePass);
            }
            int jungleIndex = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Jungle")); // 丛林
            GenPass junglepass = tasks[jungleIndex];
            for (int k = 1; k < ModContent.GetInstance<Configs>().JungleInt + 1; k++)
            {
                tasks.Insert(jungleIndex + k, junglepass);
            }
            int dungeonIndex = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Dungeon")); // 地牢
            GenPass dungeonpass = tasks[dungeonIndex];
            for (int l = 1; l < ModContent.GetInstance<Configs>().DungeonInt + 1; l++)
            {
                tasks.Insert(dungeonIndex + l, dungeonpass);
            }
            int gemsIndex = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Gems")); // 宝石
            GenPass gemspass = tasks[gemsIndex];
            for (int m = 1; m < ModContent.GetInstance<Configs>().GemsInt + 1; m++)
            {
                tasks.Insert(gemsIndex + m, gemspass);
            }
            int floatingIslandsIndex = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Floating Islands")); // 空岛
            GenPass floatingIslandspass = tasks[floatingIslandsIndex];
            for (int n = 1; n < ModContent.GetInstance<Configs>().FloatingIslandsInt + 1; n++)
            {
                tasks.Insert(floatingIslandsIndex + n, floatingIslandspass);
            }
            int buriedChestsIndex = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Buried Chests")); // 埋藏的宝箱		
            GenPass buriedChestspass = tasks[buriedChestsIndex];
            for (int i2 = 1; i2 < ModContent.GetInstance<Configs>().BuriedChestsInt + 1; i2++)
            {
                tasks.Insert(buriedChestsIndex + i2, buriedChestspass);
            }
            int mushroomIndex = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Mushroom Patches")); // 发光蘑菇
            GenPass mushroompass = tasks[mushroomIndex];
            for (int i3 = 1; i3 < ModContent.GetInstance<Configs>().MushroomInt + 1; i3++)
            {
                tasks.Insert(mushroomIndex + i3, mushroompass);
            }
            int statuesIndex = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Statues")); // 雕像
            GenPass statuespass = tasks[statuesIndex];
            for (int i4 = 1; i4 < ModContent.GetInstance<Configs>().StatuesInt + 1; i4++)
            {
                tasks.Insert(statuesIndex + i4, statuespass);
            }
            int desertIndex = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Full Desert")); // 沙漠
            GenPass desertpass = tasks[desertIndex];
            for (int i5 = 1; i5 < ModContent.GetInstance<Configs>().DesertInt + 1; i5++)
            {
                tasks.Insert(desertIndex + i5, desertpass);
            }
            int shimmerIndex = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Shimmer")); // 微光
            GenPass shimmerpass = tasks[shimmerIndex];
            for (int i6 = 1; i6 < ModContent.GetInstance<Configs>().ShimmerInt + 1; i6++)
            {
                tasks.Insert(shimmerIndex + i6, shimmerpass);
            }
            int altarsIndex = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Altars")); // 祭坛
            GenPass altarspass = tasks[altarsIndex];
            for (int i7 = 1; i7 < ModContent.GetInstance<Configs>().Altars + 1; i7++)
            {
                tasks.Insert(altarsIndex + i7, altarspass);
            }
            int jungleTempleIndex = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Jungle Temple")); // 丛林神庙
            GenPass jungleTemplepass = tasks[jungleTempleIndex];
            for (int i8 = 1; i8 < ModContent.GetInstance<Configs>().JungleTemple + 1; i8++)
            {
                tasks.Insert(jungleTempleIndex + i8, jungleTemplepass);
            }
            int hiveIndex = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Hives")); // 蜂巢
            GenPass hivepass = tasks[hiveIndex];
            for (int i9 = 1; i9 < ModContent.GetInstance<Configs>().Hive + 1; i9++)
            {
                tasks.Insert(hiveIndex + i9, hivepass);
            }
            int microBiomesIndex = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Micro Biomes")); // 建筑物
            GenPass microBiomespass = tasks[microBiomesIndex];
            for (int i10 = 1; i10 < ModContent.GetInstance<Configs>().MicroBiomes + 1; i10++)
            {
                tasks.Insert(microBiomesIndex + i10, microBiomespass);
            }
            #region 把世界搞砸
            if (ModContent.GetInstance<Configs>().FuckUp)
            {
                int marbleIndex2 = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Marble"));
                GenPass marble1Pass = tasks[marbleIndex2];
                for (int i6 = 1; i6 < 101; i6++)
                {
                    tasks.Insert(marbleIndex2 + i6, marble1Pass);
                }
                int graniteIndex2 = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Granite"));
                GenPass granite1Pass = tasks[graniteIndex2];
                for (int i7 = 1; i7 < 101; i7++)
                {
                    tasks.Insert(graniteIndex2 + i7, granite1Pass);
                }
                int jungleIndex2 = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Jungle"));
                GenPass jungle1pass = tasks[jungleIndex2];
                for (int i8 = 1; i8 < 101; i8++)
                {
                    tasks.Insert(jungleIndex2 + i8, jungle1pass);
                }
                int dungeonIndex2 = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Dungeon"));
                GenPass dungeon1pass = tasks[dungeonIndex2];
                for (int i9 = 1; i9 < 101; i9++)
                {
                    tasks.Insert(dungeonIndex2 + i9, dungeon1pass);
                }
                int gemsIndex2 = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Gems"));
                GenPass gems1pass = tasks[gemsIndex2];
                for (int i10 = 1; i10 < 101; i10++)
                {
                    tasks.Insert(gemsIndex2 + i10, gems1pass);
                }
                int floatingIslandsIndex2 = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Floating Islands"));
                GenPass floatingIslands1pass = tasks[floatingIslandsIndex2];
                for (int i11 = 1; i11 < 101; i11++)
                {
                    tasks.Insert(floatingIslandsIndex2 + i11, floatingIslands1pass);
                }
                int buriedChestsIndex2 = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Buried Chests"));
                GenPass buriedChests1pass = tasks[buriedChestsIndex2];
                for (int i12 = 1; i12 < 11; i12++)
                {
                    tasks.Insert(buriedChestsIndex2 + i12, buriedChests1pass);
                }
                int mushroomIndex2 = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Mushroom Patches"));
                GenPass mushroom1pass = tasks[mushroomIndex2];
                for (int i13 = 1; i13 < 101; i13++)
                {
                    tasks.Insert(mushroomIndex2 + i13, mushroom1pass);
                }
                int statuesIndex2 = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Statues"));
                GenPass statues1pass = tasks[statuesIndex2];
                for (int i14 = 1; i14 < 101; i14++)
                {
                    tasks.Insert(statuesIndex2 + i14, statues1pass);
                }
                int shimmerIndex2 = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Shimmer"));
                GenPass shimmer1pass = tasks[shimmerIndex2];
                for (int i15 = 1; i15 < 101; i15++)
                {
                    tasks.Insert(shimmerIndex2 + i15, shimmer1pass);
                }
                int altarsIndex2 = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Altars"));
                GenPass altars1pass = tasks[altarsIndex2];
                for (int i16 = 1; i16 < 101; i16++)
                {
                    tasks.Insert(altarsIndex2 + i16, altars1pass);
                }
                int jungleTempleIndex2 = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Jungle Temple"));
                GenPass jungleTemple1pass = tasks[jungleTempleIndex2];
                for (int i17 = 1; i17 < 101; i17++)
                {
                    tasks.Insert(jungleTempleIndex2 + i17, jungleTemple1pass);
                }
                int hiveIndex2 = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Hives"));
                GenPass hive1pass = tasks[hiveIndex2];
                for (int i18 = 1; i18 < 101; i18++)
                {
                    tasks.Insert(hiveIndex2 + i18, hive1pass);
                }
                int microBiomesIndex2 = tasks.FindIndex((GenPass genpass) => genpass.Name.Equals("Micro Biomes"));
                GenPass microBiomes1pass = tasks[microBiomesIndex2];
                for (int i19 = 1; i19 < 101; i19++)
                {
                    tasks.Insert(microBiomesIndex2 + i19, microBiomes1pass);
                }
            }
            #endregion
        }
    }
}
